<template>
	<view class="baseForm">
		<!-- 当前作业 -->
		<view class="activeHeight" v-if="tableList.length > 0">
			<!-- 列表 -->
			<u-list ref="tableScroll" @scrolltolower="scrolltolower" class="list" :height="listHeight"
				lowerThreshold="50px" :pagingEnabled="true">
				<u-list-item v-for="(item, index) in tableList" :key="item.id">
					<view class="card">
						<view class="flex record-title">
							<text>周转卡编号</text>
							<text>
								{{ item.turnoverCode || "无" }}
							</text>
						</view>
						<view class="flex flex-col justify-between flex-1 h-full record-content-body">
							<view class="record-content">
								<view class="record-item">
									<text>产品名称</text>
									<text>
										{{ item.materialName || "无" }}
									</text>
								</view>
								<view class="record-item">
									<text>数量:{{ item.materialQuantity || 0}}</text>
									<text>单位:
										{{ useDictionaryStore().filterDictName("MeasurementUnit", item.quantityUnit) || ""}}</text>
								</view>
								<view class="record-item">
									<text>批次: {{ item.materialBatch }}</text>
									<text>图号:{{ item.figureNumber }}</text>
								</view>
								<view class="record-item">
									<text>类型:
										{{ useDictionaryStore().filterDictName("TurnoverType", item.turnoverType) || ""}}</text>
									<text
										v-if="item.processesClassification">工序:{{ useDictionaryStore().filterDictName("ProcessType", item.processesClassification) || "无"}}</text>
								</view>
							</view>
						</view>
					</view>
				</u-list-item>
			</u-list>

			<view class="flex justify-center" v-show="tableLoading">
				<u-loading-icon color="#000a7b"></u-loading-icon>
			</view>
		</view>
		<!-- 空数据 -->
		<view v-show="tableList.length === 0 && !tableLoading">
			<u-empty mode="list" icon="http://cdn.uviewui.com/uview/empty/list.png"></u-empty>
		</view>
	</view>
</template>

<script lang="ts" setup>
	import { ref, computed, toRaw, reactive } from "vue";
	import { onShow, onPullDownRefresh, onLoad } from "@dcloudio/uni-app";
	import { http } from "@/utils/http";
	import { PageResult, TabInfo } from "@/types/type";
	import { getSecondTime, getTimes } from "@/utils/common";
	import { useDictionaryStore } from "@/stores/useDictionaryStore";
	import { useUserStore } from '@/stores/useUserStore';
	import { useProduceStore } from "@/stores/useProduceStore";

	// 实时获取
	const workOrderList = computed(
		() => JSON.parse(useProduceStore().workOrderList) || []
	);
	const crewMemberList = computed(() => JSON.parse(useProduceStore().crewMemberList));
	console.log("crewMemberList", crewMemberList.value[0])
	// 待完成数据
	const tableList = ref([]);
	const tableLoading = ref(false);
	const current = ref(0);
	const totalPage = ref(0);
	const total = ref(0);
	//列表高度
	const listHeight = ref("");

	onShow(() => {
		// #ifdef H5
		listHeight.value = "calc(100vh - 88px)";
		// #endif

		// #ifdef APP-PLUS
		listHeight.value = "calc(100vh - 48px)";
		// #endif

		tableList.value = [];
		// 获取列表
		// loadmore()
		getList()
	});
	const props = defineProps({
		turnoverCode: {
			type: String,
			default: "",
		},
	});
	async function getList() {
		const result : PageResult<any> = await http({
			method: "POST",
			url: `/mes/mesturnoverdetail/getByTurnoverCodeList?turnoverCode=${props.turnoverCode}`,
			data: {},
		});
		tableList.value = result.data;
	}
	onPullDownRefresh(() => {
		uni.stopPullDownRefresh();
	});
	const processesClassification = ref();
	async function loadmore(type ?: string) {
		try {
			current.value += 1;
			tableLoading.value = true;
			const result : PageResult<any> = await http({
				method: "POST",
				url: "/mes/mesattendancereport/queryByPage",
				data: {
					current: current.value,
					size: 20,
					data: {},
				},
			}).finally(() => {
				tableLoading.value = false;
			});
			const list = result.data;
			for (let i = 0; i < list.length; i++) {
				tableList.value.push(list[i]);
			}
			totalPage.value = result.page;
			total.value = result.total;
			type === "refresh" && uni.stopPullDownRefresh();
		} catch (e) {
			console.log(e);
		}
	}
	const scrolltolower = () => {
		totalPage.value > current.value && loadmore();
	};


	let formData = reactive({
		id: "",
		shiftId: "",
		shiftName: "",
		planNumber: "",
		actualNumber: "",
		reportDate: getTimes(Date.now()),
		reportDateA: getTimes(Date.now()),
	});
</script>

<style lang="scss" scoped>
	uni-page-body {
		height: 100%;
		background-color: #fbfbff;
	}

	.search {
		:deep(.u-search__content) {
			box-shadow: 0 1px 8px 0px rgb(19 10 236 / 8%);
		}
	}

	.baseForm {
		background-color: #fbfbff;

		.tab-bar {
			padding: 0 20px;
		}

		.upload-scan {
			padding: $uni-page-padding;
			padding-top: 5px;
			padding-bottom: 5px;
			display: flex;
			align-items: center;

			// box-shadow: 0 1px 10px 0px rgb(19 10 236 / 10%);
			.u-icon {
				margin-left: 8px;
			}
		}

		.u-line {
			padding: 10px 0;
		}
	}

	:deep(.u-textarea__field) {
		text-align: right;
	}

	.list {
		.card {
			margin: $uni-page-padding;
			margin-top: 5px;
			margin-bottom: 4px;
			border-radius: 7px;
			padding: 12px 12px 0px 12px;
			transition: all 300ms ease;
			border: 1px solid #efefef;
			background-color: #fff;

			.card-flex {
				display: flex;
				align-items: flex-start;
			}

			.right {
				flex: 1;
			}

			.title {
				font-size: 14px;
				line-height: 40px;
				height: 40px;
				margin-top: 8px;
				font-weight: bold;
				color: #101010;
				border-top: 1px solid #e5ebff;
			}

			.uni-btn {
				float: right;
				font-size: 12px;
				height: 24px;
				line-height: 24px;
				padding: 0 15px;
				margin-top: 7px;
				font-weight: 400;
			}

			.des {
				font-size: 12px;
				line-height: 20px;
				margin-bottom: 3px;
			}

			.left {
				flex-basis: calc(50% + 10px);
			}
		}
	}

	.record-title {
		display: flex;
		justify-content: space-between;
		margin: 2px 0 2px 0;
		color: $primary-color;

		uni-text:nth-child(1) {
			font-weight: bold;
			font-size: 15px;
		}

		uni-text:nth-child(2) {
			font-weight: bold;
			font-size: 15px;
			min-width: 60px;
			text-align: right;
		}
	}

	.record-item {
		margin: 7px 0 !important;
		color: #8f8e94 !important;
		word-break: break-all;
		font-size: 13px;
	}

	.record-item1 {
		color: #8f8e94 !important;
		word-break: break-all;
		font-size: 13px;
	}

	.record-content .record-item> :first-child {
		min-width: 70px !important;
	}

	:deep(.input-box) {
		// width: calc(100% - 56px);
		width: 100%;
		// border: 0.5px solid #dadbde !important;
		border-radius: 100px;
		height: 32px;
		line-height: 32px;
		box-shadow: 0 1px 8px 0px rgb(19 10 236 / 8%);
		background-color: #fff;

		.u-input {
			pointer-events: none;
			height: 32px;
			line-height: 32px;
			padding-left: 10px !important;
		}

		.uni-input-placeholder {
			color: rgb(144, 147, 153) !important;
			font-size: 14px;
		}

		.u-icon__icon {
			font-size: 22px !important;
			line-height: 22px;
			font-weight: normal;
			top: 0px;
			color: rgb(144, 147, 153) !important;
		}

		image {
			padding: 6px 6px;
			width: 20px;
			height: 20px;
		}
	}

	:deep(.search-btn) {
		width: 32px;
		height: 34px;
		margin-left: 4px;
		border-radius: 4px;
		background-color: transparent;
		border: none;

		.u-button__text {
			color: rgb(96, 98, 102) !important;
		}
	}

	:deep(.searchButton) {
		color: rgb(41, 121, 255);
		font-size: 14px;
		width: 52px !important;
		min-width: 52px !important;
		display: flex;
		justify-content: flex-start;

		.u-icon {
			margin-left: 2px !important;
			font-size: 14px;

			.u-icon__icon {
				font-size: 14px !important;
				line-height: 14px !important;
			}
		}
	}

	:deep(.u-dropdown) {
		flex: none !important;
		width: 52px;

		.u-cell-group__wrapper {
			// border: 1px solid rgb(214, 215, 217);
			// border-radius: 4px;
			border-right: 1px solid rgb(214, 215, 217);
			border-left: 1px solid rgb(214, 215, 217);
		}

		// .u-line { display: none;}
		.u-cell__body {
			padding: 8px 10px !important;
			// border: 1px solid #8f8e94;
		}

		.u-dropdown__content__mask {
			background-color: transparent;
		}
	}
</style>